﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Jocker;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MangoMes.Write.API.Applications.Login;
using MediatR;

namespace ManagoMes.Read.API.Applications.ProductionScheduling
{
    public class StepDescriptionBackHandler : IRequestHandler<StepDescriptionBackCommond, ResultsDTO<ProcessStep>>
    {
        private readonly IBateRepository<ProcessStep> _ProcessStep;
        private readonly Logincommonality _Logincommonality;

        public StepDescriptionBackHandler(IBateRepository<ProcessStep> processStep, Logincommonality logincommonality)
        {
            _ProcessStep = processStep;
            _Logincommonality = logincommonality;
        }

        /// <summary>
        /// 工序步骤反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultsDTO<ProcessStep>> Handle(StepDescriptionBackCommond request, CancellationToken cancellationToken)
        {
            try
            {
                var list = new ResultsDTO<ProcessStep>() { Code = 0 };
                var str = "SELECT * from processstep WHERE Processtepid='" + request.Stepid + "'";
                var newdate = new ProcessStep();
                DapperHelper dapperHelper = new DapperHelper();
                var OperatorName = "123";
                var OperatorTime = DateTime.Now.ToString();
                var PerformOperation = "工序步骤反填";
                _Logincommonality.Loginaddget(OperatorName, OperatorTime, PerformOperation);
                list.Data = _ProcessStep.GetAll(str, newdate, dapperHelper.MangoMesRead).ToList();
                return list;
            }
            catch (Exception)
            {

                throw;
            }
            

        }
    }
}
